/**
 * Created by lijing on 2016-06-22.
 */
$.validator.setDefaults({
    submitHandler: function () {
        savePub();
    }
});
$(document).ready(function () {
    $("#file_upload").att({
        'scriptData': {
            'id': id,
        },
        'key': "sysTag"
    });
    validate();
    $("#idSubmit").click(function (e) {
        validator.resetForm();
    });

    $("#dictTypeName").click(function () {
        $("#dictTypeName").cate({
            title: "类型",
            url: G_Path.path + "/sys/dict/json",
            liveSearch: false,
            "id": "dictType",
            "name": "dictTypeName"
        });
    });
});

function savePub() {
    $.post(G_Path.path + "/sys/tag/save", $("#mainForm").serialize(), function (text) {
        var data = $.parseJSON(text);
        if (data.success) {
            if ("view" == status) {
                history.back();
            } else {
                window.close();
            }
        } else {
            showDialogMessage(data.msg);
        }
    });
}


function validate() {
    //设置默认属性
    $("#mainForm").validate({
        rules: {
            name: {
                required: true,
                minlength: 1
            },
            tagKey: {
                required: true,
                minlength: 1
            },
            dictTypeName: {
                required: true,
                minlength: 1
            }
        },
        messages: {
            name: {
                required: "请输入名称",
                minlength: ""
            },
            tagKey: {
                required: "请输入关键字",
                minlength: ""
            },
            dictTypeName: {
                required: "请选择标签类型",
                minlength: ""
            }
        }
    });
}